package com.lagou.assignment;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 封装数据 dataBean
 */
public class DataMapper extends Mapper<LongWritable, Text, DataBean, NullWritable> {

    DataBean dataBean = new DataBean();

    /**
     * 将数据进行格式转换
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        dataBean.setRanking(1);
        dataBean.setData(Integer.parseInt(value.toString().trim()));
        context.write(this.dataBean, NullWritable.get());
    }
}
